import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_htmlful/flutter_htmlful.dart';

import '../global_cubit.dart';
import '../main.dart';
import '../model/user.dart';

class SettingPage extends StatefulWidget {
  const SettingPage({super.key});

  @override
  State<SettingPage> createState() => _SettingPageState();
}

class _SettingPageState extends State<SettingPage> {
  final TextEditingController phoneController = TextEditingController();
  final TextEditingController codeController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return BlocProvider.value(
      value: globalCubit,
      child: BlocBuilder<GlobalCubit, GlobalState>(
        builder: (BuildContext context, GlobalState state) {
          return Material(
            child: Div(
              body: [
                Div(
                  body: const [
                    Text(
                      '账号登录',
                      style: TextStyle(color: Colors.black, fontSize: 17),
                    )
                  ],
                  style: Style(
                    direction: Axis.horizontal,
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    padding: 14,
                  ),
                ),
                Img(
                  src: 'assets/images/img.png',
                  style: Style(
                    height: 275,
                  ),
                ),
                Div(
                  body: [
                    TextField(
                      controller: phoneController,
                      maxLines: 1,
                      decoration: const InputDecoration(
                        prefixIcon: Icon(Icons.password),
                        hintText: '请输入密码',
                      ),
                    ),
                    const SizedBox(height: 20),
                    TextField(
                      controller: codeController,
                      maxLines: 1,
                      decoration: InputDecoration(
                        prefixIcon: const Icon(Icons.checklist),
                        // labelText: '请输入验证码',
                        hintText: '请输入验证码',
                        suffixIcon: Padding(
                          padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
                          child: Div(
                            body: const Text(
                              '获取验证码',
                              style: TextStyle(fontSize: 11, color: Color(0xff62BDC9)),
                            ),
                            style: Style(
                              paddingTop: 6,
                              paddingBottom: 6,
                              paddingLeft: 9,
                              paddingRight: 9,
                              border: Border.all(
                                color: const Color(0xff56B5C2),
                              ),
                              radius: 10,
                            ),
                            inkWell: InkWell(
                              onTap: () {
                                debugPrint('aaaaa');
                              },
                              onLongPress: () {},
                            ),
                          ),
                        ),
                      ),
                    ),
                    Div(
                      body: [
                        Text(
                          '登录${state.user?.phone}',
                          style: const TextStyle(fontSize: 18, color: Colors.white),
                        )
                      ],
                      style: Style(
                        width: double.infinity,
                        padding: 12,
                        marginTop: 20,
                        marginBottom: 20,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        backgroundColor: const Color(0xff56B5C2),
                        radius: 1000,
                      ),
                      inkWell: InkWell(
                        onTap: () {
                          globalCubit.setUser(User(phone: phoneController.text));
                          Navigator.pop(context);
                        },
                      ),
                    )
                  ],
                  style: Style(
                    marginTop: 50,
                    paddingLeft: 34,
                    paddingRight: 34,
                  ),
                ),
              ],
              style: Style(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                paddingTop: MediaQuery.of(context).padding.top,
                backgroundColor: Colors.white,
              ),
            ),
          );
        },
      ),
    );
  }
}
